﻿<?php require_once('Connections/satphp.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE aluno SET idturma=%s, nome=%s, login=%s, senha=%s, datanascimento=%s, email=%s WHERE idaluno=%s",
                       GetSQLValueString($_POST['idturma'], "int"),
                       GetSQLValueString($_POST['nome'], "text"),
                       GetSQLValueString($_POST['login'], "text"),
                       GetSQLValueString($_POST['senha'], "text"),
                       GetSQLValueString($_POST['datanascimento'], "date"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['idaluno'], "int"));

  mysql_select_db($database_satphp, $satphp);
  $Result1 = mysql_query($updateSQL, $satphp) or die(mysql_error());

  $updateGoTo = "aluno-listar.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

$idpego=$_GET['aluno'];

mysql_select_db($database_satphp, $satphp);
$query_RS_atualizarregistro = "SELECT * FROM aluno where idaluno=$idpego;";
$RS_atualizarregistro = mysql_query($query_RS_atualizarregistro, $satphp) or die(mysql_error());
$row_RS_atualizarregistro = mysql_fetch_assoc($RS_atualizarregistro);
$totalRows_RS_atualizarregistro = mysql_num_rows($RS_atualizarregistro);

mysql_select_db($database_satphp, $satphp);
$query_RS_turma = "select idturma,nome from turma";
$RS_turma = mysql_query($query_RS_turma, $satphp) or die(mysql_error());
$row_RS_turma = mysql_fetch_assoc($RS_turma);
$totalRows_RS_turma = mysql_num_rows($RS_turma);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SATPHP</title>
<style type="text/css">
#apDiv1 {
	position:fixed;
	left:10px;
	top:244px;
	width:170px;
	height:50px;
	z-index:1;
	text-align:center;
	}
#apDiv2 {
	position:fixed;
	left:300px;
	top:244px;
	width:170px;
	height:50px;
	z-index:1;
	text-align:center;
	}
</style>
</head>

<body>


<form action="" method="post">

</form>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  <table align="center">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Idturma:</td>
      <td>
      <select name="idturma">
      <?php do { ?> 
      <option value="<?php echo $row_RS_turma['idturma'] ?>" <?php if ($row_RS_turma['idturma']==$row_RS_atualizarregistro['idturma']) echo 'selected="selected"'; ?>><?php echo $row_RS_turma['nome'] ?></option>
	 
      <?php } while ($row_RS_turma = mysql_fetch_assoc($RS_turma)); ?>
      </select>
      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Nome:</td>
      <td><input type="text" name="nome" value="<?php echo htmlentities($row_RS_atualizarregistro['nome'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Login:</td>
      <td><input type="text" name="login" value="<?php echo htmlentities($row_RS_atualizarregistro['login'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Senha:</td>
      <td><input type="text" name="senha" value="<?php echo htmlentities($row_RS_atualizarregistro['senha'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Data de nascimento:</td>
      <td><input type="text" name="datanascimento" value="<?php echo htmlentities($row_RS_atualizarregistro['datanascimento'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Email:</td>
      <td><input type="text" name="email" value="<?php echo htmlentities($row_RS_atualizarregistro['email'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td><input type="submit" value="Atualizar registro" /></td>
    </tr>
  </table>
  <input type="hidden" name="MM_update" value="form1" />
  <input type="hidden" name="idaluno" value="<?php echo $row_RS_atualizarregistro['idaluno']; ?>" />
</form>
<div id="apDiv1"><a href="aluno-apagar.php?aluno=<?php echo $idpego ?>">Para DELETAR este aluno<br />
    clique aqui</a></div>
    
<div id="apDiv2"><a href="fotoperfil.php?aluno=<?php echo $idpego ?>">Alterar foto do perfil</a></div>
</body>
</html>
<?php
mysql_free_result($RS_atualizarregistro);

mysql_free_result($RS_turma);
?>
